﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;

namespace none.Prada
{
    public static class W3WPProcessLister
    {

        public String MyProperty { get; set; }

        private static List<Process> GetProcesses(DTE dte, Boolean onlyW3WP)
        {
            List<Process> procs = new List<Process>();
            Processes processes = dte.Debugger.LocalProcesses;
            
            foreach (Process p in processes)
            {
                if (onlyW3WP)
                {                    
                    if (p.Name.ToLower().Contains("w3wp"))
                    {
                        procs.Add(p);
                    }
                }
                else
                {
                    procs.Add(p);
                }

            }
            return procs;
        }

        
        public static Dictionary<Process, System.Diagnostics.Process> GetMatchedProcesses(DTE dte, Boolean onlyW3WP)
        {
            List<Process> processes = GetProcesses(dte, onlyW3WP);
            Dictionary<Process, System.Diagnostics.Process> procs = new Dictionary<Process, System.Diagnostics.Process>();
            foreach (Process p in processes)
            {
                System.Diagnostics.Process systemProcess = FindAmongSystemProcesses(p.ProcessID);
                if (systemProcess != null)
                {
                    procs.Add(p, systemProcess);
                }
            }
            return procs;
        }

        public static System.Diagnostics.Process FindAmongSystemProcesses(Int32 Id)
        {
            return System.Diagnostics.Process.GetProcessById(Id);            
        }
        
    }
}
